﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace CControl
{
    public class Cls_Logistica
    {
        public string Activo_Nombre { get; set; }
        public string Activo_Descripcion { get; set; }
        public string Activo_Tipo { get; set; }
        public int Activo_Marca { get; set; }
        public int Activo_Cantidad { get; set; }
        public double Activo_Precio { get; set; }

        public static double mtd_Obtener_Logistica_Precio(int _Id)
        {
            try
            {
                Cls_Conexion Objconexion = new Cls_Conexion();
                SqlCommand Objcomando = new SqlCommand();
                SqlDataAdapter ObjDataAdapter = new SqlDataAdapter();
                DataTable ObjDataTable = new DataTable();

                double precio = 0;

                Objcomando.CommandType = CommandType.StoredProcedure;
                Objcomando.CommandText = "USP_S_OBTENER_LOGISTICA_PRECIO";

                Objcomando.Parameters.Add(new SqlParameter("@ACTid_activos", SqlDbType.Int));
                Objcomando.Parameters["@ACTid_activos"].Value = _Id;

                Objcomando.Connection = Objconexion.Conectar();
                Objcomando.ExecuteNonQuery();

                ObjDataAdapter.SelectCommand = Objcomando;
                ObjDataAdapter.Fill(ObjDataTable);

                Objconexion = null;
                ObjDataAdapter = null;

                if (ObjDataTable.Rows.Count > 0)
                {
                    DataRow row = ObjDataTable.Rows[0];
                    precio = Convert.ToDouble(row[2]);
                }

                return precio;
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }

        public static double mtd_Obtener_Bebidas_Precio(int _Id)
        {
            try
            {
               Cls_Conexion Objconexion = new Cls_Conexion();
               SqlCommand Objcomando = new SqlCommand();
               SqlDataAdapter ObjDataAdapter = new SqlDataAdapter();
               DataTable ObjDataTable = new DataTable();

               double precio = 0;

               Objcomando.CommandType = CommandType.StoredProcedure;
               Objcomando.CommandText = "USP_S_OBTENER_BEBIDA_PRECIO";

               Objcomando.Parameters.Add(new SqlParameter("@ACTid_activos", SqlDbType.Int));
               Objcomando.Parameters["@ACTid_activos"].Value = _Id;

               Objcomando.Connection = Objconexion.Conectar();
               Objcomando.ExecuteNonQuery();

               ObjDataAdapter.SelectCommand = Objcomando;
               ObjDataAdapter.Fill(ObjDataTable);

               Objconexion = null;
               ObjDataAdapter = null;

               if (ObjDataTable.Rows.Count > 0)
               {
                   DataRow row = ObjDataTable.Rows[0];
                   precio = Convert.ToDouble(row[2]);
               }

               return precio;
            }
            catch (Exception ex)
            {
                
                throw ex;
            }
        }

        public static DataTable mtd_Listar_Activos_Bebidas()
        {
            try
            {
                Cls_Conexion Objconexion = new Cls_Conexion();
                SqlCommand Objcomando = new SqlCommand();
                SqlDataAdapter ObjDataAdapter = new SqlDataAdapter();
                DataTable ObjDataTable = new DataTable();

                Objcomando.CommandText = "USP_S_LISTAR_ACTIVOS_BEBIDAS";

                Objcomando.Connection = Objconexion.Conectar();
                Objcomando.ExecuteNonQuery();

                ObjDataAdapter.SelectCommand = Objcomando;
                ObjDataAdapter.Fill(ObjDataTable);

                Objconexion = null;
                ObjDataAdapter = null;

                return ObjDataTable;
            }
            catch (Exception ex)
            {
                throw ex;
                //throw new Exception("System Error.");
            }
            finally
            {
                Cls_Conexion Objconexion = new Cls_Conexion();
                Objconexion.Desconectar();
            }
        }

        public static DataTable mtd_Listar_Activos_Logistica()
        {
            try
            {
                Cls_Conexion Objconexion = new Cls_Conexion();
                SqlCommand Objcomando = new SqlCommand();
                SqlDataAdapter ObjDataAdapter = new SqlDataAdapter();
                DataTable ObjDataTable = new DataTable();

                Objcomando.CommandText = "USP_S_LISTAR_ACTIVOS_LOGISTICA";

                Objcomando.Connection = Objconexion.Conectar();
                Objcomando.ExecuteNonQuery();

                ObjDataAdapter.SelectCommand = Objcomando;
                ObjDataAdapter.Fill(ObjDataTable);

                Objconexion = null;
                ObjDataAdapter = null;

                return ObjDataTable;
            }
            catch (Exception ex)
            {
                throw ex;
                //throw new Exception("System Error.");
            }
            finally
            {
                Cls_Conexion Objconexion = new Cls_Conexion();
                Objconexion.Desconectar();
            }
        }

    }
}
